A vector of levels for a factor, or the number of levels.
contrasts
A logical indicating whether contrasts should be computed. This
argument is ignored in contr.none.
Value
contr.diff returns a matrix with n rows and k columns, with
k=n-1 if contrasts is TRUE and k=n if contrasts is FALSE.
contr.none returns a matrix with n rows and n columns, except when n=2
when it returns a matrix with 2 rows and one column.
Details
These functions are used for creating contrast matrices for use in fitting penalized
analysis of variance and regression models. The columns of the resulting matrices
contain contrasts which can be used for coding a factor with n levels. The returned
value contains the computed contrasts.
contr.none returns an identity matrix except when the number of levels is 2,
in which case it returns a single contrast. contr.none ensures that all levels
of an unordered factor are treated symmetrically in a penalized regression model.
contr.diff returns a lower triangular matrix of ones if contrasts=FALSE
and the same matrix without its first column if contrasts=TRUE. This makes sure
that penalization is done on the difference between successive levels of an ordered factor.
It is not appropriate for unordered factors.